{extend name="layout:base" /}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/kindeditor/themes/default/default.css"/>
<script charset="utf-8" src="__STATIC__/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="__STATIC__/kindeditor/lang/zh-CN.js"></script>
{/block}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">修改分类</div>
        <div class="layui-card-body">
            <form class="layui-form">
                <input type="hidden" name="id" value="{$category.id}">
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">栏目名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" autocomplete="off" class="layui-input"
                               value="{$category.title}">
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">父栏目：</label>
                    <div class="layui-input-block">
                        <select name="pid" lay-filter="pid">
                            <option value="0">顶级栏目</option>
                            {volist name="category_list" id="vo"}
                            {eq name="vo.id" value="$category['pid']"}
                            <option value="{$vo.id}" selected="selected">{$vo.title}</option>
                            {else/}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/eq}
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">类型：</label>
                    <div class="layui-input-block">
                        <select name="type" lay-filter="type">
                            <option value="1" {eq name="$category['type']" value="1"}selected {/eq}>栏目</option>
                            <option value="2"  {eq name="$category['type']" value="2"}selected {/eq}>单页</option>
                            <option value="3" {eq name="$category['type']" value="3"}selected {/eq}>链接</option>
                        </select>
                    </div>
                </div>

                <div class="layui-row layui-col-space10 layui-form-item  layui-hide" style="display: none">
                    <label class="layui-form-label">图片：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="image" id="imageurl" value="{$category.image}" autocomplete="off"
                               class="layui-input"/>
                    </div>
                    <input type="button" id="btnImgUpload" value="上传图片" class="layui-btn"/>
                </div>
                <div class="layui-form-item " style="display: none">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            预览图：
                            <div id="imageView"><img src="{$category.image}" height="50"/>
                            </div>
                        </blockquote>
                    </div>
                </div>

                <div class="layui-row layui-col-space10 layui-form-item ">
                    <label class="layui-form-label">SEO标题：</label>
                    <div class="layui-input-block">
                        <input name="seo_title" class="layui-input" value="{$category.seo_title}"/>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item ">
                    <label class="layui-form-label">SEO关键词：</label>
                    <div class="layui-input-block">
                        <input name="seo_keywords" class="layui-input" value="{$category.seo_keywords}"/>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item ">
                    <label class="layui-form-label">SEO描述：</label>
                    <div class="layui-input-block">
                        <input name="seo_description" class="layui-input" value="{$category.seo_description}"/>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item activeBox" {neq name="$category['type']" value="2"}style="display: none" {/neq} >
                    <label class="layui-form-label">内容：</label>
                    <div class="layui-input-block">
                        <textarea name="content" class="layui-textarea" style="width: 100%;min-height:1000px;">{$category.content}</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="btnSave">保存</button>
                            <a class="layui-btn layui-btn-primary" href="javascript:parent.location.reload();">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form', 'element'], function () {
        var $ = layui.$, form = layui.form;

        form.on('select(type)', function(data){
            var id=data.value;
            if(id==2){
                $('.activeBox').show();
            }else{
                $('.activeBox').hide();
            }
        });

        form.on('submit(btnSave)', function (data) {
            // console.log(data.field);
            data.field.content = editor.html();
            $.post("{:url('edit')}", data.field, function (result) {
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });
            return false;
        });
    });
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('textarea[name="content"]', {
            allowFileManager: true
        });
        K('#btnImgUpload').click(function () {
            editor.loadPlugin('image', function () {
                editor.plugin.imageDialog({
                    imageUrl: K('#imageurl').val(),
                    clickFn: function (url, title, width, height, border, align) {
                        K('#imageurl').val(url);
                        editor.hideDialog();
                        K('#imageView').html('');
                        K('#imageView').append('<img src="' + url + '" height="50">');
                    }
                });
            });
        });
    });
</script>
{/block}


